﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OleDb;

namespace GSManager
{
    public class PhieuDichVu
    {
        private int _SoPhieuDichVu;
        private DateTime _NgayGiaoDich;
        
        private string _MaKhachHang;
        private decimal _TongTien;
        private decimal _TienNo;
        private string _NguoiLapPhieu;
        public int SoPhieuDichVu
        {
            get { return _SoPhieuDichVu; }
            set { _SoPhieuDichVu = value; }
        }
        public DateTime NgayGiaoDich
        {
            get { return _NgayGiaoDich; }
            set { _NgayGiaoDich = value; }
        }
        public string MaKhachHang
        {
            get { return _MaKhachHang; }
            set { _MaKhachHang = value; }
        }
        public decimal TongTien
        {
            get { return _TongTien; }
            set { _TongTien = value; }
        }
        public decimal TienNo
        {
            get { return _TienNo; }
            set { _TienNo = value; }
        }
        public string NguoiLapPhieu
        {
            get { return _NguoiLapPhieu; }
            set { _NguoiLapPhieu = value; }
        }
        public int LaySoPhieuDichVu()
        {
            OleDbConnection connect = KetNoi.KetNoiDuLieu();
            string sql = "select Max(SoPhieuDV) from PHIEUDICHVU";
            OleDbCommand cmd = new OleDbCommand(sql, connect);
            OleDbDataReader r = cmd.ExecuteReader();
            int kq = 0;
            while (r.Read())
            {
                try
                {
                    kq = (int)r[0];
                }
                catch (Exception) { }
            }
            r.Close();
            connect.Close();
            return kq;
        }
        public void LuuPhieuDichVu()
        {
            OleDbConnection connect = KetNoi.KetNoiDuLieu();
            string sql = "Insert into PHIEUDICHVU values(?,?,?,?,?,?)";
            OleDbCommand cmd = new OleDbCommand(sql, connect);
            cmd.Parameters.Add("@SoPhieuDV", OleDbType.Integer);
            cmd.Parameters.Add("@NgayGiaoDich", OleDbType.Date);

            cmd.Parameters.Add("@MaKhachHang", OleDbType.VarChar);
            cmd.Parameters.Add("@TongTien", OleDbType.Decimal);
            cmd.Parameters.Add("@TienNo", OleDbType.Decimal);
            cmd.Parameters.Add("@NguoiLapPhieu", OleDbType.VarWChar);
            cmd.Parameters[0].Value = SoPhieuDichVu;
            cmd.Parameters[1].Value = NgayGiaoDich;
            cmd.Parameters[2].Value = MaKhachHang;
            cmd.Parameters[3].Value = TongTien;
            cmd.Parameters[4].Value = TienNo;
            cmd.Parameters[5].Value = NguoiLapPhieu;
            cmd.ExecuteNonQuery();
            connect.Close();
        }
    }
}
